<template>
	<div class="agentList" v-if="show">
		<!-- 添加 -->
		<el-card class="box-card" shadow="never">
			<el-button v-no-more-click:3000 type="primary" class="add-invoice" @click="addAgent">添加</el-button>
			<el-button v-no-more-click:3000 type="danger" class="add-invoice" @click="delAgents">删除</el-button>

			<span class="down-execel">
				<Poptip v-model="showFilter" placement="bottom-end">
					<i class="el-icon-search poptip-condition-add"></i>
					<a href="javascript:;" class='poptip-condition-add'>列表查找</a>
					<div slot="content">
						<Poptip v-model="showFilterCondition" placement="bottom-start" class='poptip-condition'>
							<i class="el-icon-plus"></i>
							<!-- <a href="javascript:;" @click='getAllAgent'>添加过滤条件</a> -->
							<a href="javascript:;">添加过滤条件</a>

							<div slot="content" class="condition-list">
								<ul>
									<li v-for="(item, index) in columns" class='poptip-condition-item' :key="index" @click="addFilterCondition(item)">{{item.label}}</li>
								</ul>
							</div>
						</Poptip>

						<el-form :model="conditionForm" ref="conditionForm" label-width="120px" class="demo-dynamic" @submit.native.prevent>
							<el-form-item v-for="(condition, index) in conditionForm.condition" :label="condition.label" :key="condition.key"
							 :prop="'condition.' + index + '.value'" :rules="{
										required: true, message: condition.label + '不能为空', trigger: 'blur'
								}">
								<!-- <el-autocomplete v-if='condition.label === "工作邮箱"' v-model="formAgent.name" :fetch-suggestions="querySearch"
								 :trigger-on-focus="true" placeholder="请选择工作邮箱" @select="handleSelect" size="small">
								</el-autocomplete> -->

								<el-select v-if='condition.label === "类型"' v-model="condition.value" placeholder="请选择在职状态" size="small">
									<el-option label="全职" value="全职"></el-option>
									<el-option label="兼职" value="兼职"></el-option>
									<!-- <el-option label="离职" value="离职"></el-option> -->
								</el-select>
								<el-select v-else-if='condition.label === "代理人身份"' v-model="condition.value" placeholder="请选择代理人身份" size="small">
									<el-option label="导师" value="1"></el-option>
									<el-option label="徒弟" value="2"></el-option>
									<el-option label="不确定" value="3"></el-option>
								</el-select>

								<el-select v-else-if='condition.label === "代理人等级"' v-model="condition.value" placeholder="请选择代理人等级" size="small">
									<el-option label="初级" value="1"></el-option>
									<el-option label="中级" value="2"></el-option>
									<el-option label="高级" value="3"></el-option>
								</el-select>
								<div v-else-if='condition.label === "可接单数"' class='is_takeQuery'>
									<el-select   v-model="condition.value" placeholder="请选择接单限制" size="small">
										<el-option label="不限制接单" value="999"></el-option>
										<el-option label="不可接单" value="0"></el-option>
										<el-option label="接单数" value="3"></el-option>
									</el-select>
									<br v-if="condition.value == 3" />
									<el-input  v-if="condition.value == 3 " v-model.number="is_take"></el-input>
								</div>
								<el-date-picker
									v-model="submitTime"
									type="daterange"
									placeholder="选择日期"
									value-format="yyyy-MM-dd"
									size="small"
									:validate-event='false'
									@input = 'changInput'
									v-else-if='condition.label === "注册时间"'>
								</el-date-picker>

								<el-input v-else size="small" v-model="condition.value" @keyup.enter.native="submitsearch('conditionForm')"></el-input>
								<el-button @click.stop="removeDomain(condition)" size="mini">删除</el-button>
							</el-form-item>
						</el-form>

						<div class="btns">
							<el-button @click="submitsearch('conditionForm')" size="mini">查询</el-button>
							<el-button @click="resetForm('conditionForm')" size="mini">重置</el-button>
						</div>
					</div>
				</Poptip>
			</span>
			<span class="down-execel" @click="exportExcel('代理人表')">
				<i class="el-icon-download"></i> <a href="javascript:;">导出列表</a>
			</span>
		</el-card>

		<el-table
			id="IMTable"
			:data="tableData"
			border
			style="width: 100%"
			v-loading="loading"
			ref="multipleTable"
			height="82%"
			tooltip-effect="dark"
			@selection-change="handleSelectionChange"
			@select-all="handleSelectionChange"
			@sort-change='tableSortChange'
			:row-key="getRowKeys">
			<el-table-column show-overflow-tooltip type="selection" width="35">
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="id" label="ID" width="60"  align="left" >
				<template slot-scope="scope">{{(scope.$index+1)+(currentPage-1)*tableSize}}</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="name" label="姓名" width="120" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span :class="scope.row.status == '冻结' ? 'font_grayness' : ''">{{scope.row.name}}</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="nickname" label="昵称" width="120" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip prop="channelName" label="推荐人" width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span v-if="scope.row.channel_agent">{{ scope.row.channel_agent.name }} </span>
					<span v-else>-</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="type" label="类型" width="120" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip prop="is_take" label="可接单数(件)" width="150" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{ scope.row.is_take | agentIsTake }}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="grade" label="代理人等级" width="120" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{ scope.row.grade | agentGrade }}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="is_teacher" label="代理人身份" width="140" align="left" sortable='custom'>
				<template slot-scope="scope">
					<!--  -->
					<span :class="scope.row.is_teacher == 1 ? 'font_success' : (scope.row.is_teacher == 2 ? 'font_warning' : '')">{{ scope.row.is_teacher == 1 ? '导师' : (scope.row.is_teacher == 2 ? '徒弟' : '-') }}</span>
				</template>
			</el-table-column>
			<el-table-column
				show-overflow-tooltip
				label="导师/学生"
				width="120"
				align="left"
			>
				<template slot-scope="scope">
					<span class="font_warning" v-if="scope.row.is_teacher == 1 && scope.row.student.length != 0">{{scope.row.student.map(v => v.name).join('、')}}</span>
					<span class="font_success" v-else-if="scope.row.is_teacher == 2 && scope.row.teacher">{{scope.row.teacher.name}}</span>
					<span v-else>-</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="phone" label="手机号码" width="180" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip prop="alipay_num" label="支付宝账号" width="180" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{scope.row.alipay_num || '-'}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="id_card_number" label="身份证号" width="180" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{scope.row.id_card_number || '-'}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="register_bank" label="开户银行" width="160" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{scope.row.register_bank || '-'}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="bank_card" label="银行卡号" width="160" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{scope.row.bank_card || '-'}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="organization" label="现任机构" width="120" align="left" sortable="custome">
				<template slot-scope="scope">
					{{scope.row.organization || '-'}}
				</template>
			</el-table-column>
			<el-table-column
				width="160"
				align="left"
				label="代理师资格证"
				sortable="custom"
			>
				<template slot-scope="scope">
					<div v-if="scope.row.certificate_pic" class="img-wrap" @click.stop>
						<pre-img
							:smallImg="scope.row.certificate_pic"
							:bigImg="scope.row.certificate_pic1"
							class="pre-img">
						</pre-img>
						<!-- <div v-for="(item, index) in scope.row.certificate_pic" :key="index">
							<el-image
								:key="index"
								:src="item"
								:preview-src-list="scope.row.certificate_pic1"
							></el-image>
						</div> -->
					</div>
					<div v-else>无</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="certificate_number" label="代理师资格证编号" width="180" align="left" sortable="custom">
				<template slot-scope="scope">
					{{scope.row.certificate_number || '-'}}
				</template>
			</el-table-column>
			<el-table-column
				width="145"
				align="left"
				label="身份证"
				sortable="custom"
			>
				<template slot-scope="scope">
					<div v-if="scope.row.id_card_con_pic" class="img-wrap" @click.stop>
						<pre-img
							:smallImg="scope.row.id_card_con_pic"
							:bigImg="scope.row.id_card_con_pic1"
							class="pre-img">
						</pre-img>
						<!-- <div v-for="(item, index) in scope.row.id_card_con_pic" :key="index">
							<el-image
								:key="index"
								:src="item"
								:preview-src-list="scope.row.id_card_con_pic1"
							></el-image>
						</div> -->
					</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip min-width="110" prop="email" label="个人邮箱" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip min-width="110" prop="email_work" label="工作邮箱" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip width="130" label="在职时间(月)" align="left" prop="created_at" sortable='custom'>
				<!-- <template slot-scope="scope">{{ IncumbencyTime(scope.row) }}</template> -->
				<template slot-scope="scope">{{ scope.row.created_at | oneThejobDay }}</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip prop="created_at" label="注册时间" width="120" align="left" sortable='custom'>
				<template slot-scope="scope">{{ scope.row.created_at | formatTime }}</template>
			</el-table-column>
			<el-table-column
				fixed="right"
				width="220"
				align="center"
				label="操作"
			>
				<template slot-scope="scope">
					<div @click.stop v-if="scope.row.status != '冻结'">
						<el-button size="small" type="primary" @click.stop="lookAgent(scope.row)">编辑</el-button>
						<el-button size="small" v-no-more-click:3000 type="success" @click.stop="agentOperate(scope.row, 1)" v-if="scope.row.trial_free != 1">
							获取免审资格
						</el-button>
						<el-button size="small" v-no-more-click:3000 type="danger" @click.stop="agentOperate(scope.row, 2)" v-if="scope.row.trial_free == 1">
							取消免审资格
						</el-button>
					</div>
					<div v-else @click.stop>
						<el-button size="small" type="warning" @click.stop="unfreeze(scope.row)">解除冻结</el-button>
					</div>
				</template>
			</el-table-column>
		</el-table>

		<el-dialog title="删除说明" center :visible.sync="dialogFormVisible" >
			<el-form :model="form" :rules="rules" ref="ruleForm" label-position="top">
				<el-form-item label="离职原因" prop="reason">
					<el-input v-model="form.reason" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="离职日期" prop="leave_job_at">
					<el-date-picker v-model="form.leave_job_at" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
						:picker-options="pickerOptions0">
					</el-date-picker>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button v-no-more-click:3000 @click="dialogFormVisible = false;">取 消</el-button>
				<el-button type="primary" @click="submitDelFrom('ruleForm')" v-no-more-click:3000>确 定</el-button>
			</div>
		</el-dialog>

		<!-- 分页 -->
		<el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
		 :page-sizes="pageSizes" :page-size="Number(pageSize)" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>

		<!-- 添加弹出框 -->
		<dialogAdd ref="addDialog" @changeList="search"></dialogAdd>

		<!-- 查看详情 -->
		<agent-detail ref="agent-detail" @refresh="search"></agent-detail>

		<!-- 查看代理人数据 -->
		<agent-data ref="agent-data"></agent-data>

		<!-- 导出表格 -->
		<xy-excel-export-template ref="TerminalExportExcel"></xy-excel-export-template>
	</div>
</template>
<script>
	import {
		getAgent,
		getAgentList,
		delUser
	} from "~/api/user";
	import dialogAdd from "~/components/addUser";
	import dialogEdit from "~/components/editUser";
	import agentDetail from './detailPage/agent-detail'
	import agentData from './detailPage/agent-data'
	import preImg from '~/components/pre-img'
	import xyExcelExportTemplate from "~/components/ExcelExportTemplate";
	export default {
		head: {
			title: "代理人管理"
		},
		name: "agent",
		data() {
			return {
        baseUrl: global.baseurl,
				total: 0,
				show: true,
				dialogFormVisible: false,
				form: {
					reason: '',
					leave_job_at: ''
				},
				rules: {
					reason: [{
						required: true,
						message: '请输入离职原因',
						trigger: 'blur'
					}],
					leave_job_at: [{
						required: true,
						message: '请输入离职日期',
						trigger: 'blur'
					}]
				},
				loading: false,
				tableData: [],
				checkTable: [],
				tableSize: 10, //一页几条
				currentPage: 1, //目前在第几页
				pageSize: 10, //一页可以几条
				pageSizes: [25, 50], //一页可以几条
				pickerOptions0: {
					disabledDate(time) {
						return time.getTime() > Date.now();
					}
				},
				showFilter: false, // 控制显示筛选条件
				showFilterCondition: false,
				submitTime: [],
				conditionForm: {
					condition: []
				}, //筛选条件
				columns: [{
						label: '姓名',
						id: 1,
						parameter: 'name'
					},
					{
						label: '昵称',
						id: 13,
						parameter: 'nickname'
					},
					{
						label: '推荐人',
						id: 8,
						parameter: 'channelName'
					},
					{
						label: '手机号',
						id: 2,
						parameter: 'phone'
					},
					{
						label: '支付宝账号',
						id: 11,
						parameter: 'alipay_num'
					},
					{
						label: '身份证号',
						id: 12,
						parameter: 'id_card_number'
					},
					{
						label: '类型',
						id: 3,
						parameter: 'type'
					},
					{
						label: '代理人等级',
						id: 14,
						parameter: 'grade'
					},
					{
						label: '可接单数',
						id: 15,
						parameter: 'is_take',
					},
					{
						label: '代理人身份',
						id: 4,
						parameter: 'is_teacher'
					},
					{
						label: '开户银行',
						id: 9,
						parameter: 'register_bank'
					},
					{
						label: '银行卡号',
						id: 10,
						parameter: 'bank_card'
					},
					{
						label: '工作邮箱',
						id: 5,
						parameter: 'email_work'
					},
					{
						label: '个人邮箱',
						id: 6,
						parameter: 'email'
					},
					{
						label: '注册时间',
						id: 7,
						parameter: 'subimt_time'
					},
				],
				paramsByUser: {
					role_id: 2,
					type: "兼职,全职",
					status: '已激活,冻结'
				},
				is_take: 0
			};
		},
		components: {
			dialogAdd,
			dialogEdit,
			agentDetail,
			preImg,
			agentData,
			xyExcelExportTemplate
		},
		async asyncData({
			$axios
			}) {
			let params = {
				status: '已激活,冻结'
			}
			let res = await getAgentList($axios, params);
			let obj = {
				loading: false
			};
			if (res.data.code == 200) {
				obj.tableData = res.data.data;
				obj.pageSize = obj.tableData.length;
				obj.tableSize = obj.tableData.length;
				obj.tableEnd = obj.tableData.length;
				obj.total = res.data.page.total;

			}
			return obj;
		},
		methods: {
			// 解除代理人冻结
			unfreeze(data) {
				this.$confirm(`是否解除代理人<span class='font_success'>${data.name}</span>的冻结模式？`, '提示', {
          confirmButtonText: '确定',
					cancelButtonText: '取消',
					dangerouslyUseHTMLString: true,
        }).then(() => {
					let params = {
						agent: data.id
					}
          this.$axios.put(`api/agent/${data.id}/unfreezing`,params).then(res => {
						if (res.data.code == 200) {
							this.$alert('该代理人已成功解除冻结。', '解除成功', {
								confirmButtonText: '确定',
								center: true,
								callback: action => {
								}
							})
							this.search()
						} else {
							this.$alert(res.data.message, '提示', {
								confirmButtonText: '确定',
								center: true,
								callback: action => {
								}
							})
						}

					})
        }).catch(() => {
        })
			},
			//导出excel
			exportExcel(name) {
				let tabHandle = [
					"姓名",
					"昵称",
					"推荐人",
					"类型",
					"代理人身份",
					"师徒关系",
					"手机号码",
					"支付宝账号",
					"身份证号",
					"开户银行",
					"银行卡号",
					"现任机构",
					"代理师资格证编号",
					"个人邮箱",
					"工作邮箱",
					"在职时间(月)",
					"注册时间",
				];
				let params = {
					allPage: 2
				}
				params = Object.assign({}, this.paramsByUser)
				params.status = '已激活,冻结'
				getAgentList(this.$axios, params)
					.then(res => {
						if (res.data.code == 200) {
							if (this.tableData.length) {
								let exTableData = []
								let item = {}
								for (let i in JSON.parse(JSON.stringify(this.tableData))) {
									item = this.tableData[i]
									exTableData.push(item);
								}
								this.$refs.TerminalExportExcel.exportExcelAgent(name, tabHandle, exTableData);
							}
						}
					})
			},
			agentOperate(row, type) {
				let id = row.id,
					agent_name = row.name,
					msg = ''
				if (type == 1) {
					msg = `确认开通<span class="finish">${agent_name}</span>的免审资格吗？`
				} else if (type == 2) {
					msg = `确认取消<span class="finish">${agent_name}</span>的免审资格吗？`
				}
				this.$confirm(msg, '提示', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					center: true,
					dangerouslyUseHTMLString: true,
					type: 'warning'
				}).then(() => {
					let params = {
						trial_free: type
					}
					this.$axios.put(`/api/agent/${id}/trial_free`, params).then(res => {
						if (res.data.code == 200) {
							let msg = ''
							if (type == 1) {
								msg = '开通免审资格成功'
							} else if (type == 2) {
								msg = '取消免审资格成功'
							}
							// this.changeData()
							this.search()
							this.$message({
								type: 'success',
								message: msg
							})
						} else {
							this.$message({
								type: 'error',
								message: res.data.message
							})
						}
					}).catch(e => {})
				}).catch(e => {})
			},
			agentData(row) {
				if (window.getSelection().toString() === '') {
					this.$refs['agent-data'].showOn(row)
				}
			},
			lookAgent(row) {
				this.$refs['agent-detail'].showOn(row)
			},
			initData() {
				let that = this;
				let params = {
					status: '已激活'
				}
				getAgentList(that.$axios, params)
					.then(res => {
						if (res.data.code == 200) {
							that.tableData = res.data.data;
						}
					})
			},
			//添加
			addAgent() {
				this.$refs.addDialog.showDialog("2");
			},
			// 删除
			delAgent(val) {
				this.$confirm("是否删除代理人?", "提示", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						center: true,
						type: "warning"
					})
					.then(() => {
						delUser(this.$axios, val.id)
							.then(res => {
								if (res.data.code == 200) {
									this.$message({
										message: "删除成功",
										type: "success"
									});

									//刷新数据
									this.changeData();
								}
							})
							.catch(err => {
								console.log(err);
							});
					})
			},
			delAgents() {
				let that = this;
				if (this.checkTable.length <= 0) {
					this.$message({
						type: "warning",
						message: "请选择至少一个代理人"
					});
				} else {
					this.dialogFormVisible = true;
					//解决弹出层出现后，所选择的行数据，选择状态都变为false了，即都取消选择了。不过弹出层关闭后选择状态还是都变为false了
					// this.$nextTick(function() {
					// 	for (let i in this.checkTable) {
					// 		this.$refs.multipleTable.toggleRowSelection(this.checkTable[i]);
					// 	}
					// })
				}
			},
			submitDelFrom(formName) {
				let that = this;
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let ids = [];
						for (let i in that.checkTable) {
							ids.push(that.checkTable[i].id);
						}
						let params = {
							ids: ids,
							reason: this.form.reason,
							leave_job_at: this.form.leave_job_at
						}
						this.$axios.delete(`/api/user`, {
								params: params
						}).then(res => {
							if (res.data.code == 200) {
								this.$message({
									message: "删除成功",
									type: "success"
								});
								this.dialogFormVisible = false;
								this.search();
							} else {
								this.$message({
									message: res.data.message,
									type: "error"
								});
							}
						}).catch(e => {})
					} else {
						return false;
					}
				})
			},
			getRowKeys(row) {
				return row.id;
			},
			//刷新数据
			onChangeList() {
				this.changeData();
			},
			//获取新数据
			changeData() {
				this.paramsByUser.status = '已激活,冻结'
				getAgentList(this.$axios, this.paramsByUser)
					.then(res => {
						this.loading = false
						this.tableData = res.data.data
						this.total = res.data.page.total
						this.pageSize = res.data.page.per_page
						this.tableSize = res.data.page.per_page
						this.tableEnd = res.data.page.per_page
					})
					.catch(err => {
						console.log(err);
					});
			},

			// 多选
			handleSelectionChange(val) {
				this.checkTable = val;
			},
			//批量导出
			exportAll() {},

			//选择一页几条
			handleSizeChange(size) {
				this.paramsByUser.perPage = size
				this.paramsByUser.page = 1
				let params = Object.assign({}, this.paramsByUser)
				params.status = '已激活,冻结'
				getAgentList(this.$axios, params)
					.then(res => {
						if (res.data.code == 200) {
							this.tableData = res.data.data;
							this.total = res.data.page.total
							this.pageSize = res.data.page.per_page
        			this.tableSize = res.data.page.per_page
        			this.tableEnd = res.data.page.per_page
						}
					})
			},
			//选择第几页
			handleCurrentChange(currentPage) {
				this.currentPage = currentPage;
				// let params = this.paramsByUser
				this.paramsByUser.page = currentPage
				let params = Object.assign({}, this.paramsByUser)
				params.status = '已激活,冻结'
				getAgentList(this.$axios,  params)
					.then(res => {
						if (res.data.code == 200) {
							this.tableData = res.data.data;
						}
					})
			},
			async search() {
				this.currentPage = 1
				for (var i = 0; i < this.conditionForm.condition.length; i++) {
					let a = this.conditionForm.condition[i].parameter
					this.paramsByUser[a] = this.conditionForm.condition[i].value

					if (this.conditionForm.condition[i].parameter === 'subimt_time') {
						this.paramsByUser.created_start_time = this.submitTime[0]
						this.paramsByUser.created_end_time = this.submitTime[1]
					}
					if (this.conditionForm.condition[i].parameter === 'is_take') {
						if (this.conditionForm.condition[i].value == 3) {
							this.paramsByUser.is_take = this.is_take
						}
					}
				}

				// 处理分页数据
				delete this.paramsByUser.page

				// 处理排序状态
				delete this.paramsByUser.sort_str
				delete this.paramsByUser.sort_order
				this.$refs['multipleTable'].clearSort()
				this.loading = true
				let params = Object.assign({}, this.paramsByUser)
				params.status = '已激活,冻结'
				this.$axios.get('api/agent', {
					params: params
				})
				.then(res => {
					if (res.data.code == '200') {
						this.loading = false
						this.tableData = res.data.data
						this.total = res.data.page.total
						this.pageSize = res.data.page.per_page
						this.tableSize = res.data.page.per_page
						this.tableEnd = res.data.page.per_page
						// this.showFilter = false

					} else {
						that.loading = false;
						this.$message.error('服务器繁忙')
					}
				})
			},

			// 添加条件筛选
			addFilterCondition(item) {
				let filterItem = {
					value: '',
					label: item.label,
					parameter: item.parameter,
					key: Date.now()
				}

				if (this.conditionForm.condition.length > 0) {
					let conditionlabels = []
					for (let i = 0; i < this.conditionForm.condition.length; i++) {
						conditionlabels.push(this.conditionForm.condition[i].label)
					}
					let Check = conditionlabels.indexOf(item.label)
					Check == -1 ? this.conditionForm.condition.push(filterItem) : this.$message.error('请勿重复添加')
				} else {
					this.conditionForm.condition.push(filterItem)
				}

				this.showFilterCondition = false;
			},
			resetForm(formName) {
				this.$refs[formName].resetFields()
				this.$refs['multipleTable'].clearSort()
				this.conditionForm.condition.forEach(v => {
					if (v.value) {
						v.value = null
					}
				});
				this.showFilterCondition = false
				this.submitTime = []
				this.paramsByUser = {
					role_id: 2,
					type: "兼职,全职",
					status: '已激活,冻结'
				}
				this.$nextTick(() => {
					this.$refs[formName].clearValidate()
				})
				// this.onChangeList()
				// this.showFilter = false
			},
			submitsearch(formName) {
				let that = this
				this.$refs[formName].validate((valid, prop) => {
					// this.$refs[formName].clearValidate();
					let props = []
					for (let k in prop) {
						props.push(prop[k][0].field)

						if (prop[k][0].message = '提交时间不能为空') {
							if (that.submitTime) {
								if (that.submitTime.length > 0) {
									that.$refs[formName].clearValidate([prop[k][0].field])
									// that.search()
									let timeIndex = props.indexOf('提交时间不能为空')
									props.splice(timeIndex, 1)
								}
							} else {
								return false
							}
						}
					}
					if (props.length) {
						that.$refs[formName].validateField(props, (valid2) => {
							if (valid2) {
								return false;
							} else {
								that.showFilter = false
								that.search()
							}

						})
					} else {
						that.showFilter = false
						that.search()
					}
				})
			},
			changInput () {
				this.$refs['conditionForm'].clearValidate();
			},
			removeDomain(item) {
				delete this.paramsByUser[item.parameter]
				let index = this.conditionForm.condition.indexOf(item)
				if (index !== -1) {
					this.conditionForm.condition.splice(index, 1)
				}
				if (item.label === '提交时间') {
					this.submitTime = []
					delete this.paramsByUser.created_start_time
					delete this.paramsByUser.created_end_time
				}
				this.search()
			},
			tableSortChange(column) {
				if (column.order === 'descending') {
					this.paramsByUser.sort_str = column.prop
					this.paramsByUser.sort_order = 'desc'
				} else if (column.order === 'ascending'){
					this.paramsByUser.sort_str = column.prop
					this.paramsByUser.sort_order = 'asc'
				} else {
					delete this.paramsByUser.sort_str
					delete this.paramsByUser.sort_order
				}
				this.loading = true;
				let params = Object.assign({}, this.paramsByUser)
				params.status = '已激活,冻结'
				this.$axios.get('api/agent', {
					params: params
				})
				.then(res => {
					if (res.data.code == '200') {
						this.loading = false;
						this.tableData = res.data.data
						this.total = res.data.page.total
						this.pageSize = res.data.page.per_page;
						this.tableSize = res.data.page.per_page
						this.tableEnd = res.data.page.per_page;
					} else {
						this.$message.error('服务器繁忙')
					}
				})
			}
		},
		watch: {
			dialogFormVisible(val) {

				if (!val) {
					this.$refs['ruleForm'].resetFields();
					// for(let i = 0; i < this.checkTable.length; i++) {
					// 	this.checkTable[i] = false
					// }
					this.$refs['multipleTable'].clearSelection();
				}
			},
			tableData: {
				handler: function(val) {
					val.forEach(v => {
						v.id_card_pro_pic = []
						v.id_card_pro_pic1 = []
						v.id_card_con_pic = []
						v.id_card_con_pic1 = []
						v.certificate_pic = []
						v.certificate_pic1 = []
						if (v.certificate_thumb && v.certificate_thumb.indexOf('means') > -1) {
							v.certificate_pic.push(this.baseUrl + '/storage/upload/' + v.certificate_thumb)
							if (v.certificate && v.certificate.indexOf('means') > -1) {
								v.certificate_pic1.push(this.baseUrl + '/storage/upload/' + v.certificate)
							}
						}
						if (v.id_card_thumb) {
							let obj = JSON.parse(v.id_card_thumb)
							v.id_card_con_pic.push(this.baseUrl + '/storage/upload/' + obj.pro)
							v.id_card_con_pic.push(this.baseUrl + '/storage/upload/' + obj.con)
							if (v.id_card) {
								let obj = JSON.parse(v.id_card)
								v.id_card_con_pic1.push(this.baseUrl + '/storage/upload/' + obj.pro)
								v.id_card_con_pic1.push(this.baseUrl + '/storage/upload/' + obj.con)
							}
						}
					})
				},
				immediate: true
      }
		}
	};
</script>
<style lang='less' scoped>
	.agentList {
		height: 100%; //撑满表格
		/deep/.el-table {
			.img-wrap {
				display: flex;
				justify-content: center;
				> div {
					height: 23px;
					margin-right: 10px;
					&:nth-last-child(1) {
						margin-right: 0;
					}
				}
				.el-image {
					width: 23px;
					height: 23px;
				}
			}
		}
    .el-table {
      width: 99.9% !important;
		}
		.el-date-editor {
			width: 100%;
		}
		.el-dialog {
			max-width: 500px;
		}
	}
	.el-card {
		margin-bottom: 10px;
	}

	.el-main .ivu-poptip .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 450px;
		// height: 300px;
		overflow-y: scroll;
	}

	.el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
	}

	.demo-dynamic {
		padding-left: 10px;

		.el-form-item {
			margin-bottom: 12px;
		}

		.el-input {
			width: 240px;
		}

		.el-date-editor {
			width: 240px;
		}

		.el-button {
			padding: 9px 15px;
			vertical-align: baseline;
		}

		.el-form-item__error {
			padding-top: 0;
		}
	}

	.poptip-condition {
		display: block;
		margin-top: 10px;

		.poptip-condition-item {
			line-height: 25px;
			cursor: pointer;
		}

		.poptip-condition-add {
			font-size: 14px;
		}
	}

	.btns {
		margin-top: 10px;
	}
	.is_takeQuery {
		display: inline-block;
	}



</style>
